package com.bitsbazaar.manager;

import java.util.List;

import com.bitsbazaar.dao.BaseDao;
import com.bitsbazaar.entity.Category;
import com.bitsbazaar.entity.Product;
import com.bitsbazaar.entity.SubCategory;

public class CategoryManagerImpl implements CategoryManager {
	
	private BaseDao dao;

	public BaseDao getDao() {
		return dao;
	}

	public void setDao(BaseDao dao) {
		this.dao = dao;
	}
	
	@Override
	public Long addCategory(Category category) {
		return dao.save(category);
	}

	@Override
	public Category getCategoryById(Long Id) {
		return (Category) dao.findById(Category.class, Id);
	}

	@Override
	public List<Category> getAllCategories() {
		@SuppressWarnings("unchecked")
		List<Category> obj = (List<Category>)(List<?>)dao.getAll(Category.class);
		return obj;
	}

	@Override
	public Boolean deleteCategoryById(Long Id) {
		return dao.deleteById(Category.class, Id);
	}

	@Override
	public Boolean updateCategory(Category category) {
		return dao.update(category);
	}

	@Override
	public Long addSubCategory(SubCategory subCategory) {
		return dao.save(subCategory);
	}

	@Override
	public SubCategory getSubCategoryById(Long Id) {
		return (SubCategory) dao.findById(SubCategory.class, Id);
	}

	@Override
	public List<SubCategory> getSubCatByCatId(Long categoryId) {
		@SuppressWarnings("unchecked")
		List<SubCategory> obj = (List<SubCategory>)(List<?>)dao.findByProperty(SubCategory.class, "parentCatId", categoryId);
		return obj;
	}

	@Override
	public Boolean deleteSubCategoryById(Long Id) {
		return dao.deleteById(SubCategory.class, Id);
	}

	@Override
	public Boolean updateSubCategory(SubCategory subCategory) {
		return dao.update(subCategory);
	}

	
}
